package bots

import (
	"github.com/astaxie/beego/logs"
	"smart_home/api/models"
)

type BotInfo struct {
	Platform string
	User     *models.User
	Token    string
	Body     []byte
	Answer   interface{}
}

type BotInterface interface {
	Init()
	SetPlatform(platform string)
	SetToken(token string)
	SetBody(body []byte)
	GetAnswer() interface{}
}

func (b *BotInfo) Init() {
	logs.Debug("Init is not exists")
}

func (b *BotInfo) SetPlatform(platform string) {
	b.Platform = platform
}

func (b *BotInfo) SetToken(token string) {
	b.Token = token
}

func (b *BotInfo) SetBody(body []byte) {
	b.Body = body
}

func (b *BotInfo) GetAnswer() interface{} {
	return b.Answer
}

var botFactorys = make(map[string]BotInterface)

func AddBots(platform string, bot BotInterface) {
	if _, ok := botFactorys[platform]; !ok {
		botFactorys[platform] = bot
	}
}

func GetBotInterface(platform string) BotInterface {
	if bot, ok := botFactorys[platform]; ok {
		return bot
	}
	return nil
}
